ImageView = function (name) {
    $jf.type.Sprite.apply(this, [name]);

    var self = this;
    var hasLoadImage = false;

    /**
    * 重写设置宽度
    **/
    this.width = function (value) {
        if (arguments.length > 0) {
            if (this._propertyManager.changeValue("_width", value)) {
                this._autoResizeImage();
                this.invalidate();
            }
        } else {
            return this._propertyManager.getValue("_width");
        }
    };

    /**
    * 重写设置高度
    **/
    this.height = function (value) {
        if (arguments.length > 0) {
            if (this._propertyManager.changeValue("_height", value)) {
                this._autoResizeImage();
                this.invalidate();
            }
        } else {
            return this._propertyManager.getValue("_height");
        }
    }

    /**
    * 图片路径
    **/
    this.url = function (value) {
        if (arguments.length > 0) {
            if (this._image.url() == value) {
                return;
            }
            hasLoadImage = false;
            this._image.url(value);
        } else {
            return this._image.url();
        }
    }

    /**
    * 图片加载完毕
    **/
    this._loadImageCompleteHandler = function (event) {
        hasLoadImage = true;
        self._autoResizeImage();
        self.invalidate();
    }

    /**
    * 自动调整图片尺寸
    **/
    this._autoResizeImage = function () {
        if (hasLoadImage) {
            var hScale = this._image.imageWidth() == 0 ? 1 : this.width() / this._image.imageWidth();
            var vScale = this._image.imageHeight() == 0 ? 1 : this.height() / this._image.imageHeight();
            var scale = hScale > vScale ? hScale : vScale;
            scale = scale == 0 ? 1 : scale;
            this._image.width(scale * this._image.imageWidth());
            this._image.height(scale * this._image.imageHeight());
        }
    }

    this.imageWidth = function () {
        return this._image.imageWidth();
    }

    this.imageHeight = function () {
        return this._image.imageHeight();
    }

    this.style("overflow", "hidden");
    this._image = $jf.image(name + "_Imghandler");
    this._image.style("overflow", "hidden");
    this._image.addEventListener($jf.type.Event.COMPLETE, this._loadImageCompleteHandler);
    this.addChild(this._image);

    this.contentSelectable = false;
}

//继承EventDispatcher
$jf.inherited(ImageView,$jf.type.Sprite);
